package cn.qu.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class StringUtils {

	/**
	 * @Description: 分割字符串
	 * @Author XiaoLong.Qu
	 * @DateTime 2021年8月8日 下午10:27:32
	 * @param sb
	 * @param widthLength 分割阈值
	 * @return
	 */
	public static List<String> split(StringBuilder sb, int widthLength) {
		List<String> list = new ArrayList<>();
		BigDecimal divide = new BigDecimal(sb.length()).divide(new BigDecimal(widthLength), RoundingMode.UP);
		int ceil = divide.intValue();
		for (int i = 0; i < ceil; i++) {
			int start = i * widthLength;
			int end = (i + 1) * widthLength;
			end = end > sb.length() ? sb.length() : end;
			String string = sb.substring(start, end);
			list.add(string);
		}
		return list;
	}

}
